package marvin.webapp.common.action;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

/**
 * Common class for any web action.
 *
 */
public abstract class AbstractWebAction implements Serializable{
	
	private static final long serialVersionUID = 7057527719243346590L;
		
	/**
	 * Get the current faces view.
	 * @return the UI view root component
	 */
	protected UIViewRoot getCurrentFacesView() {
		return FacesContext.getCurrentInstance().getViewRoot();
	}
	
	protected void displayMessage(FacesMessage.Severity severity, String title, String message) {
		FacesMessage msg = new FacesMessage(severity, title, message);
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}
	
	protected boolean isOnMobile(){
		String userAgent = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("User-Agent");
		
		return userAgent.contains("iPhone");
	}
}
